package com.weic.controller;

import com.weic.pojo.User;
import com.weic.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserController {


    @Autowired
    UserService userService;

    /**
     * 用户登入跳转
     * @param uname
     * @param password
     * @return
     */
    @RequestMapping(value = "/login")
    public String login( String uname,String password){
        String view = null;
        User user = userService.findUser(uname, password);
        if(null != user){
            view = "/login/success";
        }else{
            view = "/login/fail";
        }
        System.out.println(view);
        return view;
    }

    /**
     * 获取所有用户
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getAllUser")
    public List<User> getAllUser(){
        return userService.findAllUser();
    }

}
